namespace SubhadraSolutions.Sharp.Logging.LogPublishers
{
    using SubhadraSolutions.Sharp.Logging.Contracts;
    using SubhadraSolutions.Sharp.Utils.Collections.Concurrent;
    using SubhadraSolutions.Sharp.Utils.Diagnostics;
    using SubhadraSolutions.Sharp.Utils.Diagnostics.Performance;

    public sealed class PerfCounterUpdateInfoLogPublisher : AbstractLogPublisher
    {
        #region Fields

        private static readonly PerfCounterUpdateInfoLogPublisher _instance =
            new PerfCounterUpdateInfoLogPublisher();

        #endregion Fields

        #region Constructors

        private PerfCounterUpdateInfoLogPublisher()
        {
            PerfCounterManager.Instance.AfterCountersCaptured += Instance_AfterCountersCaptured;
        }

        #endregion Constructors

        #region Properties

        public static PerfCounterUpdateInfoLogPublisher Instance
        {
            get { return _instance; }
        }

        #endregion Properties

        #region Methods

        private void Instance_AfterCountersCaptured(object sender, CountersCapturedEventArgs e)
        {
            var items = new[] { new LogStoreItem(LogItemSeverity.INFO, LogItemCategories.Technical, e.Info) };
            var args = new StoreFlushEventArgs<LogStoreItem>(items);
            raiseOnFlushEvent(args);
        }

        #endregion Methods
    }
}